import java.io.File;
import java.util.List;

public class WindowsFilenameRenamer {
    public static final String GERMAN                   = "Deutsch";
    public static final String ENGLISH_WITH_GERMAN_SUBS = "Englisch mit german Subs";
    public static final String ENGLISH                  = "Englisch";

    /**
     * @param args
     */
    public static void main(String[] args) {
        /* parameters needs to be set */
        int season = 3;
        String series = "Eastbound & Down";
        String language = ENGLISH;

        List<String> episodenames = ReadFromFile.read(series, language, season);

        File dir = new File("C:/Users/Marco/Videos/Serien/" + series + "/"
                + language + "/Staffel " + season);
        File[] dirfiles = dir.listFiles(new FileNameExtensionFilter("avi",
                "mkv", "mpg", "mov"));
        for (int i = 0; i < dirfiles.length; i++) {
            File file = dirfiles[i];
            String extension = file.getName().substring(
                    file.getName().length() - 3);
            String name = file.getName().substring(0,
                    file.getName().length() - 4);
            System.out.print(name + "    ------->    ");

            name = series + " S";

            if (season < 10) {
                name += "0";
            }

            name += season + "E";

            if (i < 9) {
                name += "0";
            }
            name += (i + 1) + " ";
            name += episodenames.get(i).trim();

            name = name.trim();
            name = name.replaceAll("\\\\", "");
            name = name.replaceAll("/", "");
            name = name.replaceAll(":", "");
            name = name.replaceAll("\\*", "");
            name = name.replaceAll("\"", "");
            name = name.replaceAll("<", "");
            name = name.replaceAll(">", "");
            name = name.replaceAll("|", "");

            System.out.println(name);
            name = dir.getAbsolutePath() + "/" + name + "." + extension;
            file.renameTo(new File(name));
        }
    }
}
